define(['jquery','treeView'],function($){
'use strict';
angular.module('common.tradeInfoSelectSingle', ['app.treeView'])

	.controller('tradeInfoSelectSingleCtrl'
			,['$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title'
			   , f])//控制器结束
    function f($rootScope, $scope, BizData, $uibModalInstance, params, title) {


   		var Model = this;
   		
   		var options = {};
//      options.dataService = sysInfoService;
		options.httpUrl = $rootScope.getServiceName();
   		options.reader = '/backcenter/tradeInfo/tree/query';
   		options.writer = '/backcenter/tradeInfo/tree/save';
   		options.deleter = '/backcenter/tradeInfo/tree/delete';
   		options.idColumnDefine = "fID";
   		options.idColumnName = "fID";
   		options.defCols = {fID:{name:"fID",type:"String",label:""},tradeCode:{name:"tradeCode",type:"String",label:""},tradeName:{name:"tradeName",type:"String",label:""},tradeFullID:{name:"tradeFullID",type:"String",label:""},tradeFullCode:{name:"tradeFullCode",type:"String",label:""},tradeFullName:{name:"tradeFullName",type:"String",label:""},nodeType:{name:"nodeType",type:"String",label:""},areaCode:{name:"areaCode",type:"String",label:""},postCode:{name:"postCode",type:"String",label:""},nodeLevel:{name:"nodeLevel",type:"Integer",label:""},nodeKind:{name:"nodeKind",type:"String",label:""},sortNo:{name:"sortNo",type:"String",label:""},fParent:{name:"fParent",type:"String",label:""},cUsercode:{name:"cUsercode",type:"String",label:""},cUsername:{name:"cUsername",type:"String",label:""},cDatetime:{name:"cDatetime",type:"Datetime",label:""},userId:{name:"userId",type:"String",label:""},version:{name:"version",type:"Integer",label:""}};
   		options.isTree = true;
   		options.parentRelation = 'fParent';
   		options.nodeKindRelation = 'nodeKind';
   		options.nodeLevelRelation = 'nodeLevel';
   		options.nodeSortRelation = "sortNo";
   		options.rootFilter = 'TradeInfo.fParent is null';
//   		options.rootFilter = 'TradeInfo.nodeLevel=2';
   		options.pathRelation = 'tradeFullID';
   		options.directDeleteMode = false;
   		options.limit = -1;
		options.orderBy = 'sortNo ASC';

   		
   		$scope.dataTree = new BizData(options);
   		//监视对象中的所有变动
//   	$scope.dataTree.deregRows = $scope.$watch('dataTree.rows',$scope.dataTree.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
   		//////////////////////////////////////////////

		
		
		//////////////////////对话框使用开始//////////////////////////////////////
		
        //模态窗口打开之后执行的事件
        $uibModalInstance.opened.then(function(){
    		//接收调用对话框的参数
            Model.title = title;  
            Model.params = params;
        	//公司
    		//设置过滤条件
//    		$scope.dataTree.filter = "AccountCaption.enterpriseNo='"+ Model.params.id +"'";//
     	
       		$scope.dataTree.refreshData();

        });  
		
        Model.ok = function () {  
	    	//保存成功
	    	//打包数据
	    	var event = {};
	    	var data = [];
	    	var sourceRow = $scope.dataTree.rows[$scope.dataTree.currentIndex];
	    	var row = {};
			//循环行中的列，判断变化点是哪一个
			for(var obj in sourceRow){
				if(obj!='$$hashKey' && obj!='userdata'){
					row[obj] = sourceRow[obj].value;
				}
			}
	    	
	    	data.push(row);
	    	event.data = data;
			$uibModalInstance.close(event);  
	    };  
	    
	    Model.cancel = function () {  
	        $uibModalInstance.dismiss('cancel');  
	    };    
		//////////////////////对话框使用结束//////////////////////////////////////
	    



	    return Model;
	    
	}	

})	
